package com.xh.xyzp.controller;

import com.xh.xyzp.common.constant.UserContext;
import com.xh.xyzp.common.domain.vo.resp.ApiResult;
import com.xh.xyzp.common.domain.vo.resp.PageResp;
import com.xh.xyzp.domain.entity.User;
import com.xh.xyzp.domain.vo.*;
import com.xh.xyzp.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author: xianghao
 * @Description:
 * @Date: 2025-04-12  10:44
 */
@Api(tags = "用户接口")
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    @ApiOperation("登录")
    @PostMapping("/login")
    public ApiResult<LoginResp> login(@RequestBody LoginReq req) {

        return ApiResult.success(userService.login(req));
    }

    @ApiOperation("注册")
    @PostMapping("/register")
    public ApiResult<Void> register(@RequestBody RegisterReq req) {
        userService.register(req);
        return ApiResult.success();
    }

    @ApiOperation("用户信息")
    @GetMapping("/info")
    public ApiResult<User> getUserInfo() {

        return ApiResult.success(userService.getUserInfo(UserContext.getUser().getId()));
    }

    @ApiOperation("用户列表")
    @PostMapping("/list")
    public ApiResult<PageResp<User>> getList(@RequestBody UserListReq req) {

        return ApiResult.success(userService.getList(req));
    }

    @ApiOperation("更新信息")
    @PostMapping("/submit")
    public ApiResult<User> submitUserInfo(@RequestBody User user) {
        return ApiResult.success(userService.submitUserInfo(user));
    }

    @ApiOperation("管理员更新信息")
    @PostMapping("/admin/submit")
    public ApiResult<Void> adminSubmitUserInfo(@RequestBody UserAdminSubmitReq user) {
        userService.submitUserInfoByAdmin(user);
        return ApiResult.success();
    }



}
